import { request, type ApiResponse } from ".";

import type { User } from "@/stores/types";

export interface RegisterParams {
  email?: string;
  password?: string;
  confirmPassword?: string;
}

export function register(params: RegisterParams) {
  return request<ApiResponse<User>>("/register", {
    method: "POST",
    body: JSON.stringify(params),
  });
}

export interface LoginParams {
  email: string;
  password: string;
  token: string;
}
export function login(data: LoginParams) {
  return request<ApiResponse<User> & { token: string }>("/login", {
    method: "POST",
    body: JSON.stringify(data),
  });
}

export function resetPassword(email: string) {
  return request<ApiResponse>("/reset-password", {
    method: "POST",
    body: JSON.stringify({ email }),
  });
}

export interface ChangePasswordParams {
  oldPassword?: string;
  newPassword?: string;
  confirmPassword?: string;
}

export function changePassword(params: ChangePasswordParams) {
  return request<ApiResponse<User>>("/user/password", {
    method: "PUT",
    body: JSON.stringify(params),
  });
}

export interface ProfileParams {
  number: string;
  name: string;
  gender?: "MALE" | "FEMALE";
  class: string;
  college: string;
  major: string;
}

export function getProfile() {
  return request<ApiResponse<User>>("/user/profile", {
    method: "GET",
  });
}

export function updateProfile(params: ProfileParams) {
  return request<ApiResponse<User>>("/user/profile", {
    method: "PUT",
    body: JSON.stringify(params),
  });
}
